<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSTL 核心标签库</title>
</head>
<body>
	<c:out value="第一个JSTL程序" />
	<br />
	<c:out value="你使用的浏览器是 " />
	<c:out value="${header['User-Agent']}" />
	<br />
	<c:out value="${param.data}" default="No Data" />
	<br />
	<c:out value="<p>有特殊字符</p>" />
	<!-- <p>被转义输出 -->
	<br />
	<c:out value="<p>有特殊字符</p>" escapeXml="false" />
	<!-- <p>作为了HTML标记 -->
	<br />
	<hr />
	<c:set value="${1+2}" var="result" scope="session" />
	<%=session.getAttribute("result")%><br />

	<jsp:useBean id="customer" class="jsp.bean.Customer" />
	<c:set value="Sean" target="${customer}" property="name" />
	<c:out value="${customer.name}" />
	<br />

	<c:remove var="result" />
	<%=session.getAttribute("result")%><br />

	<hr />

	<c:catch var="errorMessage">
		<%
			String str = "NaN";
			int i = Integer.parseInt(str);
		%>
	</c:catch>
	${errorMessage}
	<br />

	<hr />

	<c:if test="${param.name == 'admin'}" var="condition">
		Hello Admin!
	</c:if>
	执行结果为 ${condition}
	<br />

	<hr />

	<%
		String[] arrays = new String[5];
		arrays[0] = "This";
		arrays[1] = "is";
		arrays[2] = "a";
		arrays[3] = "nice";
		arrays[4] = "pen";

		request.setAttribute("arrays", arrays);

		java.util.Map<String, String> map = new java.util.HashMap<>();
		map.put("1", "one");
		map.put("2", "two");
		map.put("3", "three");
		map.put("4", "four");
		map.put("5", "five");
		map.put("6", "six");
		request.setAttribute("map", map);
	%>
	<!-- 迭代数组 -->
	<c:forEach items="${arrays}" var="item">
		${item}&nbsp;
	</c:forEach>
	<br />
	<c:forEach items="${arrays}" var="item" begin="1" end="4" step="2">
		${item}&nbsp;
	</c:forEach>
	<br />
	
	<!-- 迭代Map -->
	<c:forEach items="${map}" var="item">
		${item.key}->${item.value}&nbsp;
	</c:forEach>
	<br />

	<!-- 普通循环 -->
	<c:forEach begin="1" end="10" var="item">
		${item}&nbsp;
	</c:forEach>
	<br />
	
	<!-- varStatus四个属性 -->
	<c:forEach items="${arrays}" var="item" varStatus="s">
		index : ${s.index} &nbsp; 
		count : ${s.count} &nbsp;
		first : ${s.first} &nbsp;
		last : ${s.last} &nbsp;<br/>
	</c:forEach>
	<br />
	
	<hr />
	<!-- forTokens -->
	<c:forTokens items="a-b-c-d-e-f-g" delims="-" var="item">
		${item}&nbsp;
	</c:forTokens>
	<br/>
	<!-- 使用多个分隔符 -->
	<c:forTokens items="a-b;c-d;e-f,g" delims="-;," var="item">
		${item}&nbsp;
	</c:forTokens>
	
	<hr />
	
	<c:url value="/helloWorld.jsp" var="urlVar">
		<c:param name="name" value="参数"/>
	</c:url>
	${urlVar}
</body>
</html>